using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Core.GameObjects.Stats;

namespace WorldEditor.SystemManager.Stats
{
    public partial class Stats : UserControl
    {
        public Stats()
        {
            InitializeComponent();
        }

        private void Stats_Load(object sender, EventArgs e)
        {
            //Load Stats from Stats Manager
            LoadStats();
        }
        /// <summary>Load All stats from Stat manager</summary>
        private void LoadStats()
        {
            //Clear out all prev items
            lbStats.Items.Clear();
            //Load all stats
            foreach (Stat stat in StatManager.Stats)
            {
                lbStats.Items.Add(stat);
            }
        }

        private void tsbAdd_Click(object sender, EventArgs e)
        {
            AddStat();
        }
        /// <summary>Add A Stat</summary>
        private void AddStat()
        {
            //New Stat
            Stat stat = new Stat("New Stat");
            //Add to List Box and to Stat Manager
            lbStats.Items.Add(stat);
            StatManager.Stats.Add(stat);
        }

        private void tsbDelete_Click(object sender, EventArgs e)
        {
            DeleteStat();
        }

        private void DeleteStat()
        {
            Stat stat = (Stat)lbStats.SelectedItem;

            StatManager.Stats.Remove(stat);

            lbStats.Items.Remove(stat);
        }

        private void lbStats_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadStatProperties((Stat)lbStats.SelectedItem);
        }

        private void LoadStatProperties(Stat stat)
        {
            pgStats.SelectedObject = stat;
        }

        private void pgStats_SelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e)
        {
            LoadStats();
        }
    }
}
